#include <iostream>
#include <pthread.h>
#include <cstdio>
#include <string>
#include <unistd.h>
#include <vector>
const int num = 10;
using namespace std;
void *routine(void *args)
{
    sleep(1);
    string name = static_cast<const char *>(args);
    delete (char *)args;
    int cnt = 1;
    while (cnt--)
    {
        cout << "new 线程名字：" << name << endl;
        sleep(1);
    }
    return nullptr;
}
int main()
{
    vector<pthread_t> tids;
    for (int i = 0; i < num; i++)
    {
        pthread_t tid;
        char *id = new char[64];
        snprintf(id, 64, "thread-%d", i);
        int n = pthread_create(&tid, nullptr, routine, id);
        if (n == 0)
        {

            tids.push_back(tid);
        }
        else
            continue;
    }
    for (int i = 0; i < num; i++)
    {
        int n = pthread_join(tids[i], nullptr);
        if (n == 0)
        {
            cout << "等待新线程成功" << endl;
        }
    }
    return 0;
}